1
Lezione 7: Apprendimento Trasferito – Sfruttare la Conoscenza
EvoClass-AI002Lecture 7
00:00

Benvenuto nella Lezione 7, in cui presentiamo Apprendimento Trasferito. Questa tecnica consiste nel riutilizzare un modello di apprendimento profondo già addestrato su un vasto dataset generico (come ImageNet) e adattarlo per risolvere un compito nuovo e specifico (come la nostra sfida FoodVision). È fondamentale per ottenere risultati all'avanguardia in modo efficiente, soprattutto quando i dataset etichettati sono limitati.

1. Il Potere dei Pesi Pre-addestrati

I reti neurali profonde imparano le caratteristiche in modo gerarchico. I livelli inferiori imparano concetti fondamentali (bordi, angoli, texture), mentre i livelli più profondi combinano queste informazioni in concetti complessi (occhi, ruote, oggetti specifici). L'idea chiave è che le caratteristiche fondamentali apprese all'inizio sono universalmente applicabili applicabili in gran parte dei domini visivi.

Componenti dell'Apprendimento Trasferito

  • Compito di Origine: Addestramento su 14 milioni di immagini e 1000 categorie (ad esempio, ImageNet).
  • Compito Obiettivo: Adattamento dei pesi per classificare un dataset molto più piccolo (ad esempio, le nostre categorie specifiche FoodVision).
  • Componente Sfruttato: La grande maggioranza dei parametri della rete — gli strati di estrazione delle caratteristiche — viene riutilizzata direttamente.
Vantaggi in Efficienza
L'apprendimento trasferito riduce drasticamente due principali barriere risorsa: Costo Computazionale (si evita di addestrare l'intero modello per giorni) e Richiesta di Dati (è possibile ottenere alta accuratezza con centinaia, piuttosto che migliaia, di esempi di addestramento).
train.py
TERMINALbash — pytorch-env
> Ready. Click "Run" to execute.
>
TENSOR INSPECTOR Live

Run code to inspect active tensors
Question 1
What is the primary advantage of using a model pre-trained on ImageNet for a new vision task?
It requires less labeled data than training from scratch.
It completely eliminates the need for any training data.
It guarantees 100% accuracy immediately.
Question 2
In a Transfer Learning workflow, which part of the neural network is typically frozen?
The final Output Layer (Classifier Head).
The Convolutional Base (Feature Extractor layers).
The entire network is usually unfrozen.
Question 3
When replacing the classifier head in PyTorch, what parameter must you first determine from the frozen base?
The batch size of the target data.
The input feature size (the output dimensions of the last convolutional layer).
The total number of model parameters.
Challenge: Adapting the Classifier Head
Designing a new classifier for FoodVision.
You load a ResNet model pre-trained on ImageNet. Its last feature layer outputs a vector of size 512. Your 'FoodVision' project has 7 distinct food classes.
Step 1
What is the required Input Feature size for the new, trainable Linear Layer?
Solution:
The Input Feature size must match the output of the frozen base layer.
Size: 512.
Step 2
What is the PyTorch code snippet to create this new classification layer (assuming the output is named `new_layer`)?
Solution:
The output size of 512 is the input, and the class count 7 is the output.
Code: new_layer = torch.nn.Linear(512, 7)
Step 3
What is the required Output Feature size for the new Linear Layer?
Solution:
The Output Feature size must match the number of target classes.
Size: 7.